Skip to content

Pick Gradle distribution based on client JVM version#7534

Merged
timtebeek merged 2 commits intomainfrom
tim/gradle-java25-support
Apr 30, 2026
Merged

Pick Gradle distribution based on client JVM version#7534
timtebeek merged 2 commits intomainfrom
tim/gradle-java25-support

Conversation

@timtebeek
Copy link
Copy Markdown
Member

Summary

  • OpenRewriteModelBuilder previously hardcoded a fallback Gradle version of 8.12, which can't host its daemon on Java 24+ or Java 25+. Projects without a gradle-wrapper.properties therefore fail to build their tooling model on newer JDKs.
  • Replace the constant with defaultGradleVersion(int javaFeatureVersion) that maps the running Java version to the lowest compatible distribution per the Gradle compatibility matrix:
    • Java <= 23 -> 8.12 (unchanged)
    • Java 24 -> 8.14.3
    • Java 25+ -> 9.1.0
  • Java version is read from java.specification.version (Java 8 compatible); the existing org.openrewrite.test.gradleVersion system-property override and wrapper-detection paths are untouched.
  • Added OpenRewriteModelBuilderTest to lock in the version mapping.

Notes / open questions

  • Gradle 9.x daemons require Java 17+. That's not a regression here since clients on Java <17 still resolve to 8.12, but worth flagging.
  • Tooling API client jar version isn't bumped in this PR; the existing client supports driving the newer daemons we now request.
  • Consider whether 8.14.3 / 9.1.0 should be parameterized (e.g. read from a properties file) so we can advance them without code changes — happy to follow up if preferred.

Test plan

  • ./gradlew :rewrite-gradle-tooling-model:model:test --tests "org.openrewrite.gradle.toolingapi.OpenRewriteModelBuilderTest" passes locally
  • Manually exercise OpenRewriteModelBuilder.forProjectDirectory from a project without a wrapper, on Java 25, and confirm the daemon starts
  • CI green

The Tooling API daemon defaults to the same JVM as the client, so the
hardcoded 8.12 fallback fails on Java 24+ and Java 25+. Map the running
Java version to the lowest Gradle distribution that can host its daemon
(8.12 for <=23, 8.14.3 for 24, 9.1.0 for 25+) instead.
8.14.3 supports Java 8 through 24, so a separate 8.12 baseline isn't
needed. Only Java 25+ still requires the Gradle 9 line.
@timtebeek timtebeek marked this pull request as ready for review April 30, 2026 14:18
@timtebeek timtebeek requested a review from shanman190 April 30, 2026 14:18
@timtebeek
Copy link
Copy Markdown
Member Author

Making this change now, as we're seeing downstream test failures when running on Java 25

@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Apr 30, 2026
@timtebeek timtebeek merged commit c4774bb into main Apr 30, 2026
1 check passed
@timtebeek timtebeek deleted the tim/gradle-java25-support branch April 30, 2026 20:23
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Apr 30, 2026
timtebeek added a commit that referenced this pull request May 1, 2026
8.14.4 has a Kotlin DSL regression that breaks `plugins {}` blocks with
local `val` declarations (16 :rewrite-gradle:test failures); 8.14.3 has
no such regression and matches the pre-#7534 default for Java < 25.
timtebeek added a commit that referenced this pull request May 1, 2026
* Revert JVM-based Gradle distribution picker, pin to 8.14.4

Replaces the per-JVM-version dispatch added in #7534 with a single
hardcoded Gradle distribution. Removes the now-unused helpers and
their test.

* Replace -b with rootProject.buildFileName for Gradle 9 support

Gradle 9 dropped -b. When the caller passes a build file at a
non-conventional location, write a temporary settings.gradle with
only rootProject.buildFileName, deleting it in the same finally
block as the init script.

* Skip settings.gradle existence check when build file is conventional

* Gate the settings.gradle path on Gradle 9+, keep -b for Gradle 8

Determine the Gradle version from the explicit useGradleVersion call
or from gradle-wrapper.properties when useBuildDistribution is in
play. Existing tests on Gradle 8 keep using -b. The settings.gradle
path now writes with CREATE_NEW so it can never overwrite a
user-supplied file, and the cleanup deletes only files we actually
wrote (settingsWritten flag).

* Inline settings.gradle write next to path determination

Move the Files.write call up into the same block that decides we
need a temporary settings file, and collapse the two nested
try/finally blocks into one outer finally that handles both init
and settings cleanup. settingsWritten still gates the delete so a
race-introduced or pre-existing user file is never touched.

* Simplify version selection and collapse outer try/finally

* Pin Tooling-API client default to Gradle 8.14.3

8.14.4 has a Kotlin DSL regression that breaks `plugins {}` blocks with
local `val` declarations (16 :rewrite-gradle:test failures); 8.14.3 has
no such regression and matches the pre-#7534 default for Java < 25.
@sullis
Copy link
Copy Markdown
Contributor

sullis commented May 2, 2026

nice work @timtebeek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants